home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2221 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  50 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: mike1r@aol.com (Mike1R)
  3. Newsgroups: comp.lang.c++
  4. Subject: Overloaded methods and base classes
  5. Date: 16 Jan 1996 11:06:11 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4dgidj$4gk@newsbf02.news.aol.com>
  9. Reply-To: mike1r@aol.com (Mike1R)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. I've got a somewhat interesting C++ question. I can't find any reference
  13. to this case in Ellis and Stroustrup.
  14.  
  15. Given the following:
  16.  
  17. class A
  18. {
  19.  public:
  20.   virtual void M(void) const;
  21. };
  22.  
  23. class B : public A
  24. {
  25.  public:
  26.   virtual void M(void); // This overloads A::M since not const
  27. };
  28.  
  29. class C
  30. {
  31.  public:
  32.   void foo( A* theA );
  33. };
  34.  
  35. void C::foo( A* theA ) // theA is of class B
  36. {
  37.  theA->M();
  38. }
  39.  
  40. When compiling, the Mac MetroWerks PowerPC CW5 compiler gives a warning
  41. that B::M hides A::M. This warning is expected. However, the compiler
  42. generates code such that C::foo() calls A::M() rather than B::M().
  43.  
  44. Is this a proper C++ implementation, is it a compiler bug, or is it
  45. implementation dependent? Would the result be different if M() were not a
  46. virtual function?
  47.  
  48. I don't normally monitor this group, so would please copy all responses to
  49. my e-mail address mike1@aol.com. Thanks.
  50.